import React, { Component, Suspense } from 'react';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import { connect } from 'dva';
import PageLoading from '@/components/PageLoading';
import { FormattedMessage } from 'umi-plugin-react/locale';
import { Form, Tabs } from 'antd';
import UnknownProblem from './UnknownProblem';
import OpenQuestion from './OpenQuestion';
import ManualProblem from './ManualProblem';
import DocumentQa from './DocumentQa';
import ModelGeneration from './ModelGeneration';
import styles from "./index.less";
import SessionRecordModal from './sessionRecordModal';

const TabPane = Tabs.TabPane
const FormItem = Form.Item;
@connect(({ process, loading }) => ({
  process,
  loading: loading.effects['waitingLearningIssue/fetch'],
}))

class WaitingLearningIssue extends Component {
  constructor(props) {
    super(props);
    this.state = {
      a: 0,
      b: 0,
      c: 0,
      d: 0,
      f: 0,
      id: this.props.location.params !== undefined ? '2' : '1',
      keyNum: "1"
    };
  }

  componentDidMount() { }

  callback = (key) => {
    if (key === "2") {
      this.OpenQuestionRef.getFtch();
    };
    if (key === "3") {
      this.ManualProblemRef.getFtch()
    };
    if (key === "4") {
      this.ModelGenerationRef.getFtch();
    };
    if (key === "5") {
      this.DocumentQaRef.getFtch()
    };
  }

  totala = (a) => {
    this.setState({ a, })
  }

  totalb = (b) => {
    this.setState({ b, })
  }

  totalc = (c) => {
    this.setState({ c, })
  }

  totald = (d) => {
    this.setState({ d, })
  }

  totalf = (f) => {
    this.setState({ f, })
  }

  //打开会话记录模态框
  openSessionRecordModal = row => {
    this.SessionRecordModal.initQuery(row)
  }

  render() {
    return (
      <Suspense fallback={<PageLoading />}>
        <PageHeaderWrapper>
          <div className={styles.backgroundp}>
            <div className='tabYs'>
              <Tabs defaultActiveKey={this.state.id} onChange={this.callback}>
                <TabPane forceRender={true} tab={<span>未知问题{`(${this.state.a})`}</span>} key="1">
                  <UnknownProblem totala={this.totala} openSessionRecordModal={this.openSessionRecordModal} />
                </TabPane>
                <TabPane forceRender={true} tab={<span>未解决问题{`(${this.state.b})`}</span>} key="2">
                  <OpenQuestion totalb={this.totalb} onRef={ref => this.OpenQuestionRef = ref} openSessionRecordModal={this.openSessionRecordModal} />
                </TabPane>
                {/* <TabPane forceRender={true} tab={<span>转人工问题{`(${this.state.c})`}</span>} key="3"> */}
                {/*   <ManualProblem totalc={this.totalc} onRef={ref => this.ManualProblemRef = ref} openSessionRecordModal={this.openSessionRecordModal} /> */}
                {/* </TabPane> */}
                <TabPane forceRender={true} tab={<span>模型生成{`(${this.state.d})`}</span>} key="4">
                  <ModelGeneration totald={this.totald} onRef={ref => this.ModelGenerationRef = ref} openSessionRecordModal={this.openSessionRecordModal} />
                </TabPane>
                <TabPane forceRender={true} tab={<span>文档问答{`(${this.state.f})`}</span>} key="5">
                  <DocumentQa totalf={this.totalf} onRef={ref => this.DocumentQaRef = ref} openSessionRecordModal={this.openSessionRecordModal} />
                </TabPane>
              </Tabs>
            </div>
          </div>
          <SessionRecordModal ref={ref => this.SessionRecordModal = ref} />
        </PageHeaderWrapper>
      </Suspense>
    );
  }
}
export default connect(({ user }) => ({ // 全局数据
  currentUser: user.currentUser,
}))(Form.create()(WaitingLearningIssue));
